import React, { Component } from 'react';
import { ScrollView, RefreshControl } from 'react-native';
import { executor, toast } from '../utils';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'

export default class RefreshScrollView extends Component {
  state = { refreshing: false }
  onRefresh = () => {
    executor(this.props.refetch)
      .then(({res}) => {
        if (res) {
          toast(this.props.chinese?'刷新成功':'Refresh success');
        }
        this.setState({refreshing: false});
      });
    this.setState({refreshing: true});
  }
  render() {
    return (
      <KeyboardAwareScrollView removeClippedSubviews={true} style={this.props.style} refreshControl={<RefreshControl refreshing={this.state.refreshing} onRefresh={this.onRefresh}/>}>
        {this.props.children}
      </KeyboardAwareScrollView>
    );
  }
}